<?php
session_start();

function checkUser() {
  if ((!isset($_SESSION['validUser'])) || ($_SESSION['validUser'] != true)) {
	$_SESSION['destinationURI'] = $_SERVER['REQUEST_URI'];
    header('Location: uml_login.php');
  }
}

function getPassword($user) {
  $sql = 'SELECT password FROM users WHERE user="' . $user . '"';
  try {
    $dbh = new PDO('sqlite:./uml.db', null, null);
    if(!is_object($r = $dbh->query($sql))) {
      throw(new Exception('DB'));
    }
    $dbh = null;
    $r = $r->fetch();
  } catch (Exception $e) {
    die("<p>Database error!</p>");
  }
  if(isset($r['password'])) {
    return $r['password'];
  }
  else {
    return '';
  }
}

?>
